package com.my.structuraltype.proxy.dynamic;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class TalkHandler implements InvocationHandler {
	
	private Object target;
	
	public TalkHandler(Object target) {
		this.target = target;
	}

	@Override
	// proxy,生成的代理类,实现了目标类的接口
	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable {
		System.out.println("proxy start...");
		
//		((ITalk)proxy).talk("");// cause endless loop
//		System.out.println(proxy.toString());
//		System.out.println(proxy.hashCode());
//		System.out.println(proxy.equals(""));这三个方法都重写了,所以调用的话会发生死循环
		
		System.out.println(proxy.getClass());// 该方法没有重写
		
		System.out.println(proxy.getClass());
		
		method.invoke(target, args);
		
		System.out.println("proxy end...");
		return null;
	}

}
